package com.ds.console.controller;

import com.ds.common.Page;
import com.ds.common.PageInfo;
import com.ds.common.R;
import com.ds.console.bo.TFileBo;
import com.ds.console.service.TFileService;
import com.ds.console.vo.TFileVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 文件上传记录控制器
 *
 * @author fusheng
 * @since 2024-04-11
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/tFile")
public class TFileController {

    private final TFileService tFileService;

    /**
     * 新增
     */
    @PostMapping("/insert")
    public R<String> insert(@Validated @RequestBody TFileBo param) {
        boolean flag = tFileService.insert(param);
        return flag ? R.ok() : R.failed();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R<String> update(@Validated @RequestBody TFileBo param) {
        boolean flag = tFileService.update(param);
        return flag ? R.ok() : R.failed();
    }

    /**
     * 删除
     */
    @GetMapping("/delete/{id}")
    public R<String> delete(@PathVariable Long id) {
        boolean flag = tFileService.delete(id);
        return flag ? R.ok() : R.failed();
    }

    /**
     * 单个查询
     */
    @GetMapping("/select/{id}")
    public R<TFileVo> select(@PathVariable Long id) {
        return R.ok(tFileService.select(id));
    }

    /**
     * 列表查询
     */
    @PostMapping("/list")
    public R<PageInfo<TFileVo>> list(@RequestBody Page<TFileBo> param) {
        return R.ok(tFileService.selectPage(param));
    }
}
